package com.tfjybj.itoo.exam.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.TeacherCourseTeachClassEntity;
import com.tfjybj.itoo.exam.model.SelectTeacherTeachClassModel;
import com.tfjybj.itoo.exam.model.TeacherCourseTeachClassModel;
import com.tfjybj.itoo.exam.model.TemporaryClassStudentModel;
import com.tfjybj.itoo.exam.provider.service.TeacherCourseTeachClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TeacherCourseTeachClassController
 * teacherCourseTeachClass表
 *
 * @author 郭满亮
 * @version 2.0.0
 * @since 2.0.0 2019-02-01 19:19:48
 */
@Api(tags = {"teacherCourseTeachClass表接口"})
@RequestMapping(value = "/teacherCourseTeachClass")
@RestController
public class TeacherCourseTeachClassController {

    @Resource
    private TeacherCourseTeachClassService teacherCourseTeachClassService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TeacherCourseTeachClassModel
     * @return 添加的结果
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TeacherCourseTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
		if (StringUtils.isEmpty(model.getTeacherId())){
            return ItooResult.build(ItooResult.FAIL, "teacherId为空");
        }
		if (StringUtils.isEmpty(model.getCourseId())){
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        TeacherCourseTeachClassEntity teacherCourseTeachClassEntity = new TeacherCourseTeachClassEntity();
        BeanUtils.copyProperties(model, teacherCourseTeachClassEntity);
        teacherCourseTeachClassService.save(teacherCourseTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        teacherCourseTeachClassService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        teacherCourseTeachClassService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TeacherCourseTeachClassModel
     * @return 修改后的结果
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "根据id修改teacherCourseTeachClass")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TeacherCourseTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
		if (StringUtils.isEmpty(model.getTeacherId())){
            return ItooResult.build(ItooResult.FAIL, "teacherId为空");
        }
		if (StringUtils.isEmpty(model.getCourseId())){
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        TeacherCourseTeachClassEntity teacherCourseTeachClassEntity = new TeacherCourseTeachClassEntity();
        BeanUtils.copyProperties(model, teacherCourseTeachClassEntity);
        teacherCourseTeachClassService.updateById(teacherCourseTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TeacherCourseTeachClass
     *
     * @param id 主键id
     * @return 根据id查找的结果
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TeacherCourseTeachClassEntity teacherCourseTeachClassEntity = teacherCourseTeachClassService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teacherCourseTeachClassEntity);
    }

    /**
     * 分页查询所有TeacherCourseTeachClass
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return 分页查询的结果
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "分页查询所有TeacherCourseTeachClass")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
								   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<TeacherCourseTeachClassEntity> teacherCourseTeachClasss = teacherCourseTeachClassService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teacherCourseTeachClasss);
    }
	
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 面对面建组教师输入4位数字
     *
     * @param temporaryClassStudentModels   教师信息
     * @return 临时组成员
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "面对面建组教师输入4位数字")
    @PostMapping(value = {"/saveTeacher"})
    public ItooResult saveTeacher(@RequestBody TemporaryClassStudentModel temporaryClassStudentModels) {
        return teacherCourseTeachClassService.saveTeacher(temporaryClassStudentModels);
    }

    /**
     * 面对面建组将输入同样key值的学生统计出来
     *
     * @param temporaryClassStudentModels   学生信息
     * @return 临时组成员
     * @author 郭满亮
     * @since 2.0.0 2019-02-01 19:19:48
     */
    @ApiOperation(value = "面对面建组将输入同样key值的学生统计出来")
    @PostMapping(value = {"/saveStudent"})
    public ItooResult saveStudent(@RequestBody TemporaryClassStudentModel temporaryClassStudentModels) {
        return teacherCourseTeachClassService.saveStudent(temporaryClassStudentModels);
    }

    /**
     * 建立上课班,将老师、学生添加到上课班
     * @param temporaryClassStudentModels 所有学生和教师
     * @return 创建是否成功
     * @author 郭满亮
     * @since 2019年2月9日16:10:09
     */
    @ApiOperation(value = "建立上课班,将老师、学生添加到上课班")
    @PostMapping(value = {"/saveTeachClass"})
    public ItooResult saveTeachClass(@RequestBody TemporaryClassStudentModel temporaryClassStudentModels) {
        return  teacherCourseTeachClassService.saveTeachClass(temporaryClassStudentModels);
    }

    /**
     * 教师面对面添加学生
     *
     * @param studentCode   学生学号
     * @param keyText 4位数字
     * @return 临时组所有成员
     * @author 郭满亮
     * @since 2.0.0 2019年2月24日19:07:33
     */
    @ApiOperation(value = "教师面对面添加学生")
    @PostMapping(value = {"/saveAddStudent/{studentCode}/{keyText}"})
    public ItooResult saveAddStudent(@ApiParam(value = "学生学号", required = true) @PathVariable String studentCode,
                                     @ApiParam(value = "4位数字", required = true) @PathVariable String keyText) {
        return teacherCourseTeachClassService.saveAddStudent(studentCode,keyText);

    }
    /**
     * 教师面对面移除学生
     *
     * @param studentSet   全部教师信息
     * @return 移除结果
     * @author 郭满亮
     * @since 2.0.0 2019年2月24日19:07:33
     */
    @ApiOperation(value = "教师面对面移除学生")
    @PostMapping(value = {"/saveRemoveStudent"})
    public ItooResult saveRemoveStudent(@RequestBody TemporaryClassStudentModel studentSet) {
        return teacherCourseTeachClassService.saveRemoveStudent(studentSet);

    }

    /**
     * 根据教师id和课程id查询上课班
     *
     * @param teacherId 教师id
     * @param courseId 课程id
     * @return  上课班
     * @author 郭满亮
     * @since 2019年2月27日16:04:58
     */
    @ApiOperation(value = "根据教师id和课程id查询上课班")
    @GetMapping(value = {"/getTeachClass/{teacherId}/{courseId}"})
    public ItooResult getTeachClass(@ApiParam(value = "教师id", required = true) @PathVariable String teacherId,
                                                            @ApiParam(value = "课程id", required = true) @PathVariable String courseId){
        List<SelectTeacherTeachClassModel> teachClassList = teacherCourseTeachClassService.getTeachClass(teacherId,courseId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teachClassList);
    }
}    
